package serverproject.service;

import java.util.logging.Logger;

import serverproject.model.Account;
import serverproject.model.RankEnum;

import javolution.util.FastMap;

public class AccountService
{
	private FastMap<String, Account>	accountList	= new FastMap<String, Account>();

	@SuppressWarnings("unused")
	private static Logger				logger		= Logger.getLogger("AccountService.class");

	public static final AccountService getInstance()
	{
		return SingletonHolder.instance;		
	}
	
	private AccountService()
	{
		accountList.put("id", new Account("id", "남중", "id", RankEnum.과장));		
	}

	@SuppressWarnings("synthetic-access")
	private static class SingletonHolder
	{
		protected static final AccountService	instance	= new AccountService();
	}

	/**
	 * 로그인 성공시 true 실패시 false
	 * 
	 * @param id
	 * @param passwd
	 * @return
	 */
	public Account login(String id, String passwd)
	{
		if (!accountList.containsKey(id))
			return null;

		if (!accountList.get(id).getPassword().equals(passwd))
			return null;

		return accountList.get(id);
	}

	/**
	 * 계정 생성 성공시 true 실패시 false
	 * 
	 * @param id
	 * @param name
	 * @param passwd
	 * @param rankEnum
	 * @return
	 */
	public boolean makeAccount(String id, String name, String passwd, RankEnum rankEnum)
	{
		if (accountList.containsKey(id))
			return false;

		Account account = new Account(id, name, passwd, rankEnum);

		accountList.put(id, account);

		return true;
	}
}
